SqlCeException: The column cannot be modified. [ Column name = id ]

Posted by pek on Stack Overflow See other posts from Stack Overflow or by pek
Published on 2010-03-25T14:52:33Z Indexed on 2010/03/25 14:53 UTC
Read the original article Hit count: 1313

Filed under:
|

I am simply trying to add a single row in the database but I keep getting an exception. I created a local database and added a single table: users. It consists of two columns: "id" and "name". I only made the id primary key (not auto-increment or anything else).

When I run the following code:

    string execPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);
    string dbfile = execPath + @"\LocalDatabase.sdf";
    SqlCeConnection conn = new SqlCeConnection("datasource=" + dbfile);
    conn.Open();
    string command = "INSERT INTO users VALUES('1','pek')";
    Debug.WriteLine(command);
    SqlCeCommand comm = conn.CreateCommand();
    comm.CommandText = command;
    comm.ExecuteNonQuery();

I get the following Exception at "comm.ExecuteNonQuery();":

SqlCeException was unhandled

The column cannot be modified. [ Column name = id ]

What's with the "modified" part?

© Stack Overflow or respective owner

Related posts about sqlce

Related posts about compact-framework